package xyz.lne.researchgroupmanage.security;

import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import xyz.lne.researchgroupmanage.config.SecurityProperties;
import xyz.lne.researchgroupmanage.service.dataTransferObject.JwtUserDTO;
import xyz.lne.researchgroupmanage.util.RedisUtils;

/**
 * Designed By Lne.
 * 2021/3/5 9:20
 */
@Service
@AllArgsConstructor
public class OnlineUserService {
    private final RedisUtils redisUtils;
    private final SecurityProperties properties;

//    保存在线token
    public void save(JwtUserDTO jwtUserDTO, String token){
        redisUtils.set(properties.getOnlineKey()+token, jwtUserDTO.getUserId());
    }

//    退出登录
    public void logout(String token){
        String key = properties.getOnlineKey() + token;
        redisUtils.del(key);
    }

//    获取用户id
    public Integer getOne(String token){
        return (Integer) redisUtils.get(properties.getOnlineKey() + token);
    }
}
